home *** CD-ROM | disk | FTP | other *** search
- /* PUtils_TextMaster Utilities
-
- File name: PUtils_TextMaster.C
- Function: Utilities for the Prototyper specific code.
- History: 5/9/91 Original by Prototyper 3.0 */
-
-
-
- #include "PCommonTextMaster.h" /* Common */
- #include "Common_TextMaster.h" /* Common */
- #include "PUtils_TextMaster.h" /* This file */
-
- /* ======================================================= */
-
- /* Routine: TrapAvailable */
- /* Purpose: See if trap is available, non-available traps all have a unique address */
-
- Boolean TrapAvailable (trapNumber,tType) /* See if a trap is available */
- short trapNumber;
- short tType;
- {
- #define UnimplementedTrapNumber 0xA89F /* Unimplemented trap number */
- Boolean theResult;
-
- theResult = (NGetTrapAddress(trapNumber, tType) != GetTrapAddress(UnimplementedTrapNumber));/* Check the two traps */
- return(theResult);
- }
-
-
- /* ======================================================= */
-
- /* Routine: GetUserEvent */
- /* Purpose: See if any user events are available */
-
- void GetUserEvent(UserEventPRec TheUserEvent)
- {
- UserEventHRec NextUserEvent; /* The next user event */
-
- TheUserEvent->ID = UserEvent_None; /* Set ID to no events are available */
- if (UserEventList != NIL) /* Get first entry in the list */
- {
- HLock((Handle)UserEventList); /* Lock for safety */
- TheUserEvent->ID = (*UserEventList)->ID; /* The event ID */
- TheUserEvent->ID2 = (*UserEventList)->ID2; /* The optional ID */
- TheUserEvent->Data1 = (*UserEventList)->Data1; /* The optional data */
- TheUserEvent->Data2 = (*UserEventList)->Data2; /* The optional data */
- TheUserEvent->theHandle = (*UserEventList)->theHandle;/* The optional handle */
- NextUserEvent = (*UserEventList)->Next; /* The next list */
-
- DisposHandle((Handle)UserEventList); /* Remove this list item */
- UserEventList = NextUserEvent; /* Make the next item the new first item */
- }
- }
-
-
- /* ======================================================= */
-
- /* Routine: Add_UserEvent */
- /* Purpose: Add a user event */
-
- void Add_UserEvent( ID, ID2, Data1, Data2, theHandle)
- short ID;
- short ID2;
- long Data1;
- long Data2;
- Handle theHandle;
- {
- UserEventHRec NewUserEvent; /* The new user event */
- UserEventHRec theUserEvent; /* The user event */
-
- NewUserEvent = (UserEventHRec)NewHandle(sizeof(UserEventRec));/* Allocate a record */
- if (NewUserEvent != NIL) /* Only do if we got the new record */
- {
- HLock((Handle)NewUserEvent); /* Lock for safety */
- (*NewUserEvent)->ID = ID; /* The event ID */
- (*NewUserEvent)->ID2 = ID2; /* The optional ID */
- (*NewUserEvent)->Data1 = Data1; /* The optional data */
- (*NewUserEvent)->Data2 = Data2; /* The optional data */
- (*NewUserEvent)->theHandle = theHandle; /* The optional handle */
- (*NewUserEvent)->Next = NIL; /* No next item after this one */
-
- if (UserEventList == NIL) /* See if anyone is in the list yet */
- UserEventList = NewUserEvent; /* Make this one the first in the list */
- else /* Not the first in the list */
- {
- theUserEvent = UserEventList; /* Get the first one */
- while ((*theUserEvent)->Next != NIL) /* Get the next one */
- {
- theUserEvent = (*theUserEvent)->Next;
- }
- (*theUserEvent)->Next = NewUserEvent; /* Tack on to the end */
- }
- }
- }
-
- /* ======================================================= */
-
-
- /* This is a routine used to open a user selected file */
- /* Return TRUE for opened the file OK, else return FALSE */
- Boolean Do_The_Open_File (NumberOfTypes)
- short NumberOfTypes;
- {
- short Screen_Width, Screen_Height; /* Size of the current screen */
- Point Where; /* Used for placing the SF dialog */
- Boolean OpenedOK; /* Flag to return */
-
- Screen_Width = screenBits.bounds.right - screenBits.bounds.left;/* Width of this screen */
- Screen_Height = screenBits.bounds.bottom - screenBits.bounds.top;
-
- Where.h = (Screen_Width / 2) - (304 / 2); /* Place to put this dialog */
- Where.v = (Screen_Height / 4) - (104 / 2);
- if (Where.v < 60)
- Where.v = 60;
- InitCursor();
- SFGetFile(Where, "/pNot used", NIL, NumberOfTypes, &typeList, NIL, &Reply);
-
- OpenedOK = FALSE; /* Init to did not open the file */
- if (Reply.good) /* Only do if the user did not cancel */
- {
- /* inputFileName = Reply.fName; */
- ErrorCode = FSOpen(&Reply.fName, Reply.vRefNum, &inputRefNum);/* Open the file */
- if (ErrorCode != 0) /* See if we did not open it cleanly */
- {
- ErrorCode = FSClose(inputRefNum); /* Close it, it may have been left open from before */
- ErrorCode = FSOpen(&Reply.fName, Reply.vRefNum, &inputRefNum);/* Try the open again */
- }
-
- if (ErrorCode != 0) /* See if we did not open it cleanly */
- {
- ErrorCode = FSClose(inputRefNum); /* Close it if we can, safety */
- SysBeep(20); /* Just beep at the user, caller can do more */
- }
- else
- {
- ErrorCode = SetVol(NIL, inputRefNum); /*Set to this volume for later opens */
- OpenedOK = TRUE; /* Flag that we are open OK */
- }
- }
- else
- {
- inputRefNum = 0; /* We did not open */
- inputFileName[0] = 0; /* No name for a file */
- }
- return(OpenedOK);
- }
-
-
- /* ======================================================= */
-
-
-
- /* This is a routine used to save a user selected file */
- /* Return TRUE for opened the file OK, else return FALSE */
- Boolean Do_The_Save_File (creator, fileType)
- OSType creator;
- OSType fileType;
- {
- short Screen_Width, Screen_Height; /* Size of the current screen */
- Point Where; /* Used for placing the SF dialog */
- Boolean OpenedOK; /* Flag to return */
- short theVolRefNum; /* Volume to save the file in */
-
- Screen_Width = screenBits.bounds.right - screenBits.bounds.left;/* Width of this screen */
- Screen_Height = screenBits.bounds.bottom - screenBits.bounds.top;
-
- Where.h = (Screen_Width / 2) - (304 / 2); /* Place to put this dialog */
- Where.v = (Screen_Height / 4) - (104 / 2);
- if (Where.v < 60)
- Where.v = 60;
- InitCursor();
- SFPutFile(Where, "\pSave as : ", "\pUntitled.Text", NIL, &Reply);
- /* outputFileName = Reply.fName; */ /* Save the output file name */
- theVolRefNum = Reply.vRefNum; /* Save the volume refnum */
- OpenedOK = FALSE; /* Init to did not open the file */
- if (Reply.good) /* Only do if the user did not cancel */
- {
- ErrorCode = FSDelete(&Reply.fName, theVolRefNum); /* Delete an older file */
- ErrorCode = Create(&Reply.fName, theVolRefNum, creator, fileType);/* Create the file */
- ErrorCode = FSOpen(&Reply.fName, theVolRefNum, &outputRefNum);/* Try to open the file */
-
- if (ErrorCode == 0) /* See if we opened it cleanly */
- {
- ErrorCode = SetFPos(outputRefNum, fsFromStart, 0); /* Start at file beginning */
- ErrorCode = SetVol(NIL, outputRefNum); /* Set for later saves */
- OpenedOK = TRUE; /* We opened the file OK */
- }
- else
- {
- ErrorCode = FSClose(outputRefNum); /* Close it if we can, safety */
- SysBeep(20); /* Just beep at the user, caller can do more */
- outputRefNum = 0; /* Make sure the refnum is inited */
- }
- }
- return(OpenedOK);
- }
-
-
- /* ======================================================= */
-
-
-
- /* Setup a dialog or alert item */
- void SetupTheItem( theDialog, ItemID, SizeIt, ShowIt,EnableIt,SetTheMax,thePosition, ExtraData, StringID)
- DialogPtr theDialog;
- short ItemID;
- Boolean SizeIt;
- Boolean ShowIt;
- Boolean EnableIt;
- Boolean SetTheMax;
- Rect *thePosition;
- long ExtraData;
- short StringID;
- {
- Rect tempRect; /* Temporary rectangle */
- short DType; /* Type of dialog item */
- Handle DItem; /* Handle to the dialog item */
- ControlHandle CItem; /* Control handle */
-
- GetDItem(theDialog,ItemID,&DType,&DItem,&tempRect); /* Get the item handle and size */
- CItem = (ControlHandle)DItem; /* Change to control handle */
- if (SizeIt) /* Have to resize all CDEF connected controls */
- SizeControl(CItem, tempRect.right-tempRect.left, tempRect.bottom-tempRect.top);/* Size it */
- *thePosition = tempRect; /* Pass back the zone location and size */
- if (ExtraData != NIL) /* See if extra data for a CDEF */
- (*CItem)->contrlData = (Handle)ExtraData; /* Send it */
- if (StringID != 0) /* See if a CDEF and needs the title set again*/
- {
- GetIndString(sTemp,StringID,1); /* Get the string */
- SetCTitle(CItem,sTemp); /* Set the string */
- }
- if (EnableIt) /* See if enable or disable the zone */
- HiliteControl (CItem,0); /* Enable the zone */
- else
- HiliteControl (CItem,255); /* Dim the zone */
- if (SetTheMax)
- SetCtlMax(CItem,12345); /* Set the flag to the CDEF */
- if (ShowIt)
- ShowControl(CItem); /* Show it to activate it */
-
- }
-
- /* ======================================================= */
-
-